package com.haoshuang.zhouzhoubang.ui.page.home.settings.rate

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.TeamSettingsInfoBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class TeamRateSetViewModel : BaseViewModel() {

    /**
     * 修改门店分成比例
     */
    val updateTeamRateData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun updateTeamRate(
        team_rate: String,
        team_leader_rate: String,
        team_member_rate: String
    ) = netRequest {
        start { updateTeamRateData.value = StateData.Loading }
        request { ApiRepo.updateTeamRate(team_rate, team_leader_rate, team_member_rate) }
        success { updateTeamRateData.value = StateData.Success(it) }
        error { code, msg ->
            updateTeamRateData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取门店设置信息
     */
    val getTeamSettingsInfoData = StatefulMutableLiveData<ResponseBean<TeamSettingsInfoBean>>()
    fun getTeamSettingsInfo() = netRequest {
        start { getTeamSettingsInfoData.value = StateData.Loading }
        request { ApiRepo.getTeamSettingsInfo() }
        success { getTeamSettingsInfoData.value = StateData.Success(it) }
        error { code, msg ->
            getTeamSettingsInfoData.value = StateData.Error(code, msg)
        }
    }

}